#include "KeyTimer.h"

unsigned char KeyNumer;

//主函数调用的按键函数
unsigned char GetKey_Num(void)
{
	unsigned char t;
	t = KeyNumer;
	KeyNumer = 0;
	return t;
}//KeyNumer每次清零，还想要得到KeyNumer的数值的返回值，所以新建一个变量t

//----------------------------------------------------------------
//内部调用的实时扫描按键函数
unsigned char GetKeyNumer(void)
{
	unsigned char Key;	
	if(P30 == 0) Key = 7;
	if(P31 == 0) Key = 6;
	if(P32 == 0) Key = 5;
	if(P33 == 0) Key = 4;
	return Key;
}

//----------------------------------------------------------------
//定时器中断里10ms引用一次
void KeyScan(void)
{
	static unsigned char LastKey, NowKey;
	LastKey = NowKey;		//10ms前的
	NowKey  = GetKeyNumer();	//现在的
	
	if (LastKey == 7 && NowKey == 0) KeyNumer = 7;
	if (LastKey == 6 && NowKey == 0) KeyNumer = 6;
	if (LastKey == 5 && NowKey == 0) KeyNumer = 5;
	if (LastKey == 4 && NowKey == 0) KeyNumer = 4;	
}